package cn.bjxy.javaks.store_ms.service;

import java.lang.reflect.InvocationHandler;
import java.util.List;

import javax.xml.ws.handler.LogicalHandler;

import cn.bjxy.javaks.store_ms.entity.LogEntity;
import cn.bjxy.javaks.store_ms.ui.MainFrame;
import cn.bjxy.javaks.store_ms.ui.MyFrame;

/**
 * 界面日志信息管理业务处理代码
 * 
 * @author Administrator
 *
 */
public class UILogService {

	public static LogServiceImpl iLogService = new LogServiceImpl();

	/**
	 * 获得所有日志信息
	 * 
	 * @param frameFlag
	 *            调用标识 true 超级管理员界面调用 false 普通管理员界面调用
	 */
	public static void getAllLogs(boolean frameFlag) {

		if (frameFlag) {
			/* 走超级管理员界面 */
			List logList = iLogService.findAll();
			for (int i = 0; i < logList.size(); i++) {
				MainFrame.addRow(createRowData((LogEntity) logList.get(i)));
			}
		} else {
			List logList = iLogService.findByAdmin(MyFrame.getAdminEntity().getName());
			for (int i = 0; i < logList.size(); i++) {
				MyFrame.addRow(createRowData((LogEntity) logList.get(i)));
			}
		}
	}

	/**
	 * 封装表格日志信息
	 * 
	 * @param logEntity
	 * @return
	 */
	private static String[] createRowData(LogEntity logEntity) {
		String id = logEntity.getId();
		String adminName = logEntity.getAdmin_name();
		String content = logEntity.getContent();
		String operateType = logEntity.getOperate_type();
		String operateObj = logEntity.getOperate_obj();
		String operateObjId = logEntity.getOperate_obj_id();
		String operateDate = String.valueOf(logEntity.getOperate_date());

		String[] rowData = { id, adminName, content, operateType, operateObj, operateObjId, operateDate };
		return rowData;
	}
}
